package com.bx.implatform.growUp.controller;

import com.bx.implatform.growUp.entity.DataDictionary;
import com.bx.implatform.growUp.mapper.DataDictionaryMapper;
import com.bx.implatform.growUp.result.GrowUpBaseResult;
import com.bx.implatform.growUp.result.GrowUpBaseResultUtils;
import com.bx.implatform.growUp.service.DispatchService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * 指挥调度
 */
@RestController
@RequestMapping("/imApi/dispatch")
@Tag(name = "指挥调度大屏")
@RequiredArgsConstructor
public class DispatchController {

    private final DispatchService dispatchService;
    private final DataDictionaryMapper dataDictionaryMapper;

    @GetMapping("/eventCount")
    @Operation(summary = "事件数统计")
    public GrowUpBaseResult eventCount() {
        return GrowUpBaseResultUtils.success(dispatchService.eventCount());
    }

    @GetMapping("/eventEfficiency")
    @Operation(summary = "分公司事件处置效率排名")
    public GrowUpBaseResult eventEfficiency() {
        return GrowUpBaseResultUtils.success(dispatchService.eventEfficiency());
    }

    @GetMapping("/todayEventCount")
    @Operation(summary = "今日事件")
    public GrowUpBaseResult todayEventCount() {
        return GrowUpBaseResultUtils.success(dispatchService.todayEventCount());
    }

    @GetMapping("/eventProportion")
    @Operation(summary = "本年度事件占比分析")
    public GrowUpBaseResult eventProportion() {
        return GrowUpBaseResultUtils.success(dispatchService.eventProportion());
    }

    @GetMapping("/eventAnalyse")
    @Operation(summary = "本年度事件类型分析")
    public GrowUpBaseResult eventAnalyse(@RequestParam("查询类型：year|month") String queryType) {
        return GrowUpBaseResultUtils.success(dispatchService.eventAnalyse(queryType));
    }

    @GetMapping("/6")
    @Operation(summary = "当前发生事件清单")
    public GrowUpBaseResult method6() {
        return null;
    }

    @GetMapping("/7")
    @Operation(summary = "应急物资")
    public GrowUpBaseResult method7() {
        return null;
    }

    @GetMapping("/8")
    @Operation(summary = "应急物资统计")
    public GrowUpBaseResult method8() {
        return null;
    }

    @GetMapping("/floodSnow")
    @Operation(summary = "当期防汛/除雪")
    public GrowUpBaseResult floodSnow(@RequestParam("防汛|除雪：flood|snow") String queryType,
                                      @RequestParam("查询类型对应的key：如编织袋对应数据表中的字段bzd，以此类推") String type) {
        return GrowUpBaseResultUtils.success(dispatchService.floodSnow(queryType, type));
    }

    @GetMapping("/floodSnowQueryParam")
    @Operation(summary = "当期防汛/除雪的下拉框查询条件")
    public GrowUpBaseResult floodSnowQueryParam() {
        List<DataDictionary> list = dataDictionaryMapper.dataMap();
        Map<String, List<DataDictionary>> group = list.stream()
                .collect(Collectors.groupingBy(DataDictionary::getType));
        return GrowUpBaseResultUtils.success(group);
    }

    @GetMapping("/10")
    @Operation(summary = "各分公司值班信息")
    public GrowUpBaseResult method10() {
        return null;
    }

    @GetMapping("/11")
    @Operation(summary = "钻取：年累计事故详情")
    public GrowUpBaseResult method11() {
        return null;
    }

    @GetMapping("/12")
    @Operation(summary = "钻取：今日数据详情")
    public GrowUpBaseResult method12() {
        return null;
    }

    @GetMapping("/13")
    @Operation(summary = "钻取：应急车辆详情")
    public GrowUpBaseResult method13() {
        return null;
    }

    @GetMapping("/14")
    @Operation(summary = "钻取：应急专家详情")
    public GrowUpBaseResult method14() {
        return null;
    }

    @GetMapping("/15")
    @Operation(summary = "钻取：应急设备详情")
    public GrowUpBaseResult method15() {
        return null;
    }

    @GetMapping("/emergencyUserList")
    @Operation(summary = "钻取：救援队伍详情")
    public GrowUpBaseResult emergencyUserList(@NotNull(message = "页码不能为空")
                                              @RequestParam(defaultValue = "1") Integer page_index,
                                              @NotNull(message = "size不能为空")
                                              @RequestParam(defaultValue = "10") Integer page_size) {
        return GrowUpBaseResultUtils.success(dispatchService.emergencyUserList(page_index, page_size));
    }

}
